
package com.idealighter.game.games.zjh.util;

import static com.idealighter.game.games.zjh.struct.ZjhCardsType.BAO_ZI;
import static com.idealighter.game.games.zjh.struct.ZjhCardsType.DUI_ZI;
import static com.idealighter.game.games.zjh.struct.ZjhCardsType.ER_SAN_WU;
import static com.idealighter.game.games.zjh.struct.ZjhCardsType.SHUN_JIN;
import static com.idealighter.game.games.zjh.struct.ZjhCardsType.SHUN_ZI;

import com.idealighter.game.games.zjh.struct.ZjhCard;
import com.idealighter.game.games.zjh.struct.ZjhCards;

/**
 * 炸金花牌型比较 .
 * 
 * @date 2016年6月27日 上午11:26:14
 *
 */
public class ZjhCardsTypeComparator {

  private ZjhCardsTypeComparator() {}

  /**
   * 比牌 .
   * 
   * @param my .
   * @param other .
   * @return true:我大 false：我小
   */
  public static boolean compare(ZjhCards my, ZjhCards other) {
    if (my.getType() == ER_SAN_WU && other.getType() == BAO_ZI) {
      return true;
    } else if (my.getType() == BAO_ZI && other.getType() == ER_SAN_WU) {
      return false;
    } else if (my.getType().getPower() > other.getType().getPower()) {
      return true;
    } else if (my.getType().getPower() < other.getType().getPower()) {
      return false;
    } else if (my.getType().getPower() == other.getType().getPower()) { // 牌型相同
      if (my.getType() == SHUN_ZI || my.getType() == SHUN_JIN) { // 顺子比较最小牌,主要是考虑123是最小顺子的特殊情况
        return my.getMinCard().getPower() > other.getMinCard().getPower();
      }

      if (my.getType() == DUI_ZI) { // 对子先比较对子的大小，再比较单牌的大小
        if (my.getMidCard().getPower() == other.getMidCard().getPower()) {
          ZjhCard myCompareCard =
              my.getMaxCard().getPower() == my.getMidCard().getPower() ? my.getMinCard()
                  : my.getMaxCard();
          ZjhCard otherCompareCard =
              other.getMaxCard().getPower() == other.getMidCard().getPower() ? other.getMinCard()
                  : other.getMaxCard();

          return myCompareCard.getPower() > otherCompareCard.getPower();
        } else {
          // midCard对子牌
          return my.getMidCard().getPower() > other.getMidCard().getPower();
        }
      }

      if (my.getMaxCard().getPower() != other.getMaxCard().getPower()) {
        return my.getMaxCard().getPower() > other.getMaxCard().getPower();
      } else if (my.getMidCard().getPower() != other.getMidCard().getPower()) {
        return my.getMidCard().getPower() > other.getMidCard().getPower();
      } else if (my.getMinCard().getPower() != other.getMinCard().getPower()) {
        return my.getMinCard().getPower() > other.getMinCard().getPower();
      }

      return false;

    } else {
      return false;
    }
  }
}
